﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using YArchitech.HCLoad.Utils;

namespace YArchitech.HCLoad.Parameters
{
	public class SpaceAttributeGroup
	{
		public int PropId
		{
			get
			{
				return this.m_nPropId;
			}
		}

		public string CnName
		{
			get
			{
				return this.m_sCnName;
			}
		}

		public string EnName
		{
			get
			{
				return this.m_sEnName;
			}
		}

		public string DataCategory
		{
			get
			{
				return this.m_sDataCategory;
			}
		}

		public List<SpaceAttribute> Attributes
		{
			get
			{
				return this.m_listAttributes;
			}
		}

		public string Name
		{
			get
			{
				if (!HcUtils.IsEnglish)
				{
					return this.CnName;
				}
				return this.EnName;
			}
		}

		public bool DoPropExchange(ref XmlElement elem, bool bLoading)
		{
			if (bLoading)
			{
				string attribute = elem.GetAttribute("propid");
				this.m_nPropId = HcUtils.ToInt(attribute);
				this.m_sCnName = elem.GetAttribute("cnname");
				this.m_sEnName = elem.GetAttribute("enname");
				this.m_sDataCategory = elem.GetAttribute("datacategory");
				if (this.m_listAttributes != null)
				{
					this.m_listAttributes.Clear();
				}
				else
				{
					this.m_listAttributes = new List<SpaceAttribute>();
				}
				IEnumerator enumerator = elem.ChildNodes.GetEnumerator();
				{
					while (enumerator.MoveNext())
					{
						object obj = enumerator.Current;
						XmlNode xmlNode = (XmlNode)obj;
						if (xmlNode.Name.CompareTo("Item") == 0)
						{
							XmlElement xmlElement = xmlNode as XmlElement;
							if (xmlElement != null)
							{
								SpaceAttribute spaceAttribute = new SpaceAttribute(this);
								if (spaceAttribute.DoPropExchange(ref xmlElement, true))
								{
									this.m_listAttributes.Add(spaceAttribute);
								}
							}
						}
					}
					return true;
				}
			}
			elem.SetAttribute("cnname", this.m_sCnName);
			elem.SetAttribute("enname", this.m_sEnName);
			elem.SetAttribute("datacategory", this.m_sDataCategory);
			if (this.m_listAttributes != null)
			{
				foreach (SpaceAttribute spaceAttribute2 in this.m_listAttributes)
				{
					XmlElement newChild = elem.OwnerDocument.CreateElement("Item");
					if (spaceAttribute2.DoPropExchange(ref newChild, false))
					{
						elem.AppendChild(newChild);
					}
				}
			}
			return true;
		}

		private List<SpaceAttribute> m_listAttributes;

		private int m_nPropId;

		private string m_sCnName;

		private string m_sEnName;

		private string m_sDataCategory;
	}
}
